package 数组;

/**
 * @Project: data-structure-and-algorithms
 * @Package: 数组
 * @ClassName: t1343
 * @Author: zhouyihe
 * @Date: 2025/11/25 15:56
 * @Description: 大小为 K 且平均值大于等于阈值的子数组数目
 */
public class t1343 {
    public int numOfSubarrays(int[] arr, int k, int threshold) {
        int res = 0;
        int sum = 0;
        int index = k - 1;
        for (int i = 0; i < index; i++) {
            sum += arr[i];
        }
        while (index < arr.length) {
            sum += arr[index];
            if (sum / k >= threshold) {
                res++;
            }
            sum -= arr[index - k + 1];
            index++;
        }
        return res;
    }
}
